.TH std::basic_streambuf::setp 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::basic_streambuf::setp \- std::basic_streambuf::setp

.SH Synopsis
   protected:
   void setp( char_type* pbeg, char_type* pend );

   Sets the values of the pointers defining the put area. Specifically, after the call
   pbase() == pbeg, pptr() == pbeg, epptr() == pend.

.SH Parameters

   pbeg - pointer to the new beginning of the put area
   pend - pointer to the new end of the put area

.SH Return value

   \fI(none)\fP

.SH Example


// Run this code

 #include <array>
 #include <cstddef>
 #include <iostream>

 // Buffer for std::ostream implemented by std::array
 template<std::size_t size, class CharT = char>
 struct ArrayedStreamBuffer : std::basic_streambuf<CharT>
 {
     using Base = std::basic_streambuf<CharT>;
     using char_type = typename Base::char_type;

     ArrayedStreamBuffer()
     {
         // put area pointers to work with 'buffer'
         Base::setp(buffer.data(), buffer.data() + size);
     }

     void print_buffer()
     {
         for (char_type i : buffer)
         {
             if (i == 0)
                 std::cout << "\\\\0";
             else
                 std::cout << i;
             std::cout << ' ';
         }
         std::cout << '\\n';
     }

 private:
     std::array<char_type, size> buffer{}; // value-initialize buffer
 };

 int main()
 {
     ArrayedStreamBuffer<10> streambuf;
     std::ostream stream(&streambuf);

     stream << "hello";
     stream << ",";

     streambuf.print_buffer();
 }

.SH Output:

 h e l l o , \\0 \\0 \\0 \\0

.SH See also

   setg repositions the beginning, next, and end pointers of the input sequence
        \fI(protected member function)\fP
